package org.grpc.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.grpc.entity.AlarmMessage;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * description:
 *
 * @author shun.chen
 * @date 2022/5/12
 */
@Api(value = "测试告警回调")
@Slf4j
@RestController
public class WebHooksController {

    private List<AlarmMessage> lastList = new ArrayList<>();

    @ApiOperation("告警回调")
    @PostMapping("/alarm/test")
    public void webhook(@RequestBody List<AlarmMessage> alarmMessageList) {
        log.info(" skyWalking 报警 :{}", JSON.toJSONString(alarmMessageList));
        lastList = alarmMessageList;
        // 业务处理
    }

    @ApiOperation("告警回调")
    @PostMapping("/alarm/pro")
    public void webhook(@RequestBody JSONObject paramJson) {
        log.info(" skyWalking 报警 :{}", JSON.toJSONString(paramJson));
        // 业务处理
    }
}
